package ch.nortgram.countdown_worldcup_2014.rss;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import ch.nortgram.countdown_worldcup_2014.R;

import com.nostra13.universalimageloader.core.ImageLoader;
 
public class NewsArrayAdapter extends ArrayAdapter<String>
	{
	private final Context context;
	private final String news_title[];
	private final String news_desc[];
	private final String news_url[];
	private LayoutInflater inflater;
	private int resourceId;
 
	
	public NewsArrayAdapter(Context context, int layoutResId, String news[][])
		{
		super(context, layoutResId, news[0]);
		this.context = context;
		this.resourceId = layoutResId;
		this.news_title = news[0];
		this.news_desc 	= news[1];
		this.news_url 	= news[2];
		inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		}
 
	@Override
	public View getView(int position, View convertView, ViewGroup parent)
		{
		View row = convertView;
		if(row == null)
			{
			row = inflater.inflate(resourceId, parent, false);
			}
		
		TextView txt_news_title = (TextView)row.findViewById(R.id.news_title);
		TextView txt_news_desc = (TextView)row.findViewById(R.id.news_desc);
		final ImageView news_image = (ImageView)row.findViewById(R.id.news_img);

		txt_news_title.setText(news_title[position]);
		txt_news_desc.setText(news_desc[position]);
		
		ImageLoader.getInstance().displayImage(news_url[position], news_image);
		return row;
		}
	}
